PROJECT_PATH=$(cd `dirname $0`;pwd)
APP=$PROJECT_PATH/gameconsumer
LOGFILE=lfile.log

start()
{
    pid=`ps -ef | grep -v grep | grep -w "$APP" | awk '{print $2}' `
    if [ -z $pid ];then
        if [ ${1} ]; then   # 后台启动
            nohup $APP > ${1} 2>&1 &
        else                # 前台启动
            $APP
        fi
        echo "gameconsumer start success"
    else
        echo 'already running...'
    fi
}

stop()
{
    pid=`ps -ef | grep -v grep | grep -w "$APP" | awk '{print $2}' `
    killtype=2
    if [ ${1} ]; then
        killtype=${1}
    fi
    if [ -z $pid ];then
        echo 'no running process'
    else
        kill -s ${killtype} $pid
    fi
}

case $1 in
    'start')          start;;
    'stop')           stop;;
    'forcestop')      stop 9;;
    'startbg')        start ${LOGFILE};;
    *)
        stop
        sleep 2
        start
        #echo 'usage ./run.sh start|stop';
        ;;
esac


